<template>
  <div>
    <el-card class="box-card">
      <!-- 头部区域 -->
      <template #header>
        <div class="header">
          <span>人员管理</span>
        </div>
      </template>
      <!-- 搜索表单 -->
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="用户名：">
          <el-input v-model="this.SearchUserName" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" @click="GetUser">查询</el-button>
          <el-button icon="el-icon-refresh" type="primary">重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 人员管理列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="姓名" prop="realName">
        </el-table-column>
        <el-table-column label="联系电话" prop="phone">
        </el-table-column>
        <el-table-column label="头像">
          <template slot-scope="scope">
            <img :src="scope.row.avart" style="width: 50px; height: 50px; border-radius: 50%; object-fit: cover;"
              @click="previewavatar(scope.row.avart)">
          </template>
        </el-table-column>
        <el-table-column label="职位" prop="roleName">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- <el-dialog title="修改职位" :visible.sync="dialog" width="30%">
              <el-form>
                <el-form-item label="修改职位:">
                  <el-select placeholder="修改职位" v-model="user.roleName">
                    <el-option label="管理员" value="管理员"></el-option>
                    <el-option label="员工" value="员工"></el-option>
                  </el-select>
                </el-form-item>
              </el-form>
              <el-button @click="dialog = false">取 消</el-button>
              <el-button type="primary" @click="UserUpdate(scope.row.userId)">确定</el-button>
            </el-dialog> -->
            <!-- <el-button class="btn" type="success" icon="el-icon-reading" circle size="small"
              @click="share(scope.row.id)"></el-button> -->
            <el-button slot="reference" circle icon="el-icon-delete" size="small" type="danger"
              @click="userDelete(scope.row.userId)"></el-button>
          </template>
        </el-table-column>
        <template #empty>
          <el-empty description="没有数据" />
        </template>
      </el-table>
      <!-- 分页条 -->
      <div class="block">
        <el-pagination :current-page="this.pageNum" :page-size=this.pageSize
          :page-sizes="[3, 5, 10]" :total=this.total layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange" @current-change="handleCurrentChange">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      tableData: [],
      SearchUserName: '',
      pageNum: 1,
      pageSize: 3,
      total: 10,
      user:{
        roleName:''
      }
    }
  },
  methods: {
    //成员信息删除
    userDelete(id) {
      this.$confirm('是否删除此成员信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        request.delete("/user/UserDelete", {
          params: {
            Id: id
          }
        }).then(res => {
          if (res.data.code == '0') {
            this.$message.success("删除成功")
            this.GetUser()
            this.dialog = false
          } else {
            this.$message.error("删除失败")
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //头像预览
    previewavatar(imageUrl) {
      window.open(imageUrl, '_blank');
    },
    //分页方法
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      console.log(pageSize)
      this.GetUser()
    },

    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.GetUser()
    },
    GetUser() {
      request.get("/user/GetUser", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          userName: this.SearchUserName
        }
      }).then(res => {
        if (res.data.code == '0') {
          this.tableData = res.data.data.list
          this.total = res.data.data.total
          console.log(res.data.data)
        } else {
          this.$message.error("查询失败")
        }
      }).catch(error => {
        console.log(new error("服务异常"))
        this.$message.error("服务异常")
      })
    }
  },
  created() {
    this.GetUser()
  }

}
</script>

<style>
</style>